<?php

namespace app\sysuser\controller\trainer;

use app\common\controller\SysBackend;
use app\common\model\banxi\trainer\Trainer as TrainerModel;
use app\common\service\trainer\TrainerTimeApplyService;
use think\db\exception\PDOException;
use think\exception\ValidateException;

/**
 * 课程字典
 */
class TrainerTime extends SysBackend
{
    protected array $noNeedLogin = [];

    protected array $noNeedPermission = ['*'];

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new TrainerModel();
    }


    public function shiftSchedulingCalendar()
    {
        $param = $this->request->param(['trainerId', 'year', 'month']);
        try {
            $trainerTimeApplyService = new TrainerTimeApplyService();
            $res = $trainerTimeApplyService->shiftSchedulingCalendar($param['trainerId'],$param['year'],$param['month']);
        } catch (ValidateException|PDOException|\Exception $exception) {
            $this->fail($exception->getMessage());
        }
        $this->ok('操作成功', $res);
    }

    public function shiftScheduling()
    {
        $param = $this->request->param(['trainerId','applyDate','applyStartTime','applyEndTime','applyType']);
        try {
            $trainerTimeApplyService = new TrainerTimeApplyService();
            $res = $trainerTimeApplyService->shiftScheduling($param);
            if (!$res) {
                throw new ValidateException($trainerTimeApplyService->getError());
            }
        } catch (ValidateException|PDOException|\Exception $exception) {
            $this->fail($exception->getMessage());
        }
        $this->ok('操作成功', [], self::NOTIFICATION);
    }


}